﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace cmdb.keede.entity.Migrations
{
    public partial class UpdateApplicationInfo : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_APPLICAT_REFERENCE_APPLICAT",
                table: "ApplicationHost");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ApplicationInfo",
                table: "ApplicationInfo");

            migrationBuilder.DropIndex(
                name: "IX_ApplicationHost_ApplicationName",
                table: "ApplicationHost");

            migrationBuilder.DropColumn(
                name: "ApplicationName",
                table: "ApplicationHost");

            migrationBuilder.AlterColumn<string>(
                name: "OuterIP",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(int));

            migrationBuilder.AlterColumn<string>(
                name: "InnerIP",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(int));

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "ApplicationInfo",
                unicode: false,
                maxLength: 50,
                nullable: true,
                oldClrType: typeof(string),
                oldUnicode: false,
                oldMaxLength: 50);

            migrationBuilder.AddColumn<int>(
                name: "Id",
                table: "ApplicationInfo",
                nullable: false,
                defaultValue: 0)
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<int>(
                name: "ApplicationId",
                table: "ApplicationHost",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddPrimaryKey(
                name: "PK_ApplicationInfo",
                table: "ApplicationInfo",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationHost_ApplicationId",
                table: "ApplicationHost",
                column: "ApplicationId");

            migrationBuilder.AddForeignKey(
                name: "FK_APPLICAT_REFERENCE_APPLICAT",
                table: "ApplicationHost",
                column: "ApplicationId",
                principalTable: "ApplicationInfo",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_APPLICAT_REFERENCE_APPLICAT",
                table: "ApplicationHost");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ApplicationInfo",
                table: "ApplicationInfo");

            migrationBuilder.DropIndex(
                name: "IX_ApplicationHost_ApplicationId",
                table: "ApplicationHost");

            migrationBuilder.DropColumn(
                name: "Id",
                table: "ApplicationInfo");

            migrationBuilder.DropColumn(
                name: "ApplicationId",
                table: "ApplicationHost");

            migrationBuilder.AlterColumn<int>(
                name: "OuterIP",
                table: "VirtualHostInfo",
                nullable: false,
                oldClrType: typeof(string),
                oldUnicode: false,
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "InnerIP",
                table: "VirtualHostInfo",
                nullable: false,
                oldClrType: typeof(string),
                oldUnicode: false,
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "ApplicationInfo",
                unicode: false,
                maxLength: 50,
                nullable: false,
                oldClrType: typeof(string),
                oldUnicode: false,
                oldMaxLength: 50,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ApplicationName",
                table: "ApplicationHost",
                unicode: false,
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_ApplicationInfo",
                table: "ApplicationInfo",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationHost_ApplicationName",
                table: "ApplicationHost",
                column: "ApplicationName");

            migrationBuilder.AddForeignKey(
                name: "FK_APPLICAT_REFERENCE_APPLICAT",
                table: "ApplicationHost",
                column: "ApplicationName",
                principalTable: "ApplicationInfo",
                principalColumn: "Name",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
